# install.py - 安装脚本
import os
import sys
import subprocess
import winreg

def install_dependencies():
    """安装依赖"""
    print("正在安装依赖...")
    
    dependencies = [
        "pywin32",
        "requests"
    ]
    
    for package in dependencies:
        try:
            subprocess.check_call([sys.executable, "-m", "pip", "install", package])
            print(f"✓ 已安装 {package}")
        except subprocess.CalledProcessError:
            print(f"✗ 安装 {package} 失败")
    
    print("依赖安装完成")

def create_startup_shortcut():
    """创建启动快捷方式"""
    try:
        import winshell
        
        # 获取当前脚本路径
        if getattr(sys, 'frozen', False):
            target_path = sys.executable
        else:
            target_path = sys.executable
            script_path = os.path.abspath(__file__)
            target_path = f'"{target_path}" "{script_path}" service'
        
        # 创建启动文件夹快捷方式
        startup_folder = winshell.startup()
        shortcut_path = os.path.join(startup_folder, "ETBOX上传服务.lnk")
        
        winshell.CreateShortcut(
            Path=shortcut_path,
            Target=target_path,
            Description="ETBOX文件上传后台服务",
            Icon=(target_path, 0)
        )
        
        print("✓ 已创建开机启动快捷方式")
        
    except ImportError:
        print("✗ 无法创建开机启动快捷方式 (需要winshell)")

def main():
    print("=" * 50)
    print("      ETBOX上传工具 - 安装程序")
    print("=" * 50)
    print()
    
    # 安装依赖
    install_dependencies()
    
    # 创建开机启动
    create_startup_shortcut()
    
    print()
    print("安装完成！")
    print()
    print("使用说明:")
    print("1. 运行 'python main.py gui' 打开配置界面")
    print("2. 点击'启动后台服务'")
    print("3. 点击'添加右键菜单'")
    print("4. 现在可以在文件上右键选择'上传到ETBOX'")
    print()
    input("按回车键退出...")

if __name__ == "__main__":
    main()